namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;

    [XmlRoot("td")]
    public class TableDataCell : Cell, IXmlSerializable
    {
        public string Headers
        {
            get;
            set;
        }

        public override IElement Deserialize(string name, string type, string xml)
        {
            IElement result = null;

            if (null == type && "td".Equals(name, StringComparison.OrdinalIgnoreCase))
            {
                result = xml.Deserialize<TableDataCell>();
            }

            return result;
        }

        public override void ReadXml(XmlReader reader)
        {
            string value = reader.GetAttribute("headers");
            if (!string.IsNullOrEmpty(value))
            {
                this.Headers = value;
            }

            base.ReadXml(reader);
        }

        public override void WriteXml(XmlWriter writer)
        {
            if (!string.IsNullOrEmpty(this.Headers))
            {
                writer.WriteAttributeString("headers", this.Headers);
            }

            base.WriteXml(writer);
        }
    }
}